package com.bwf.lgqingdan.gui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bwf.lgqingdan.R;
import com.bwf.lgqingdan.entity.ArticlesBean;
import com.bwf.lgqingdan.gui.adapter.base.BaseRecycleViewAdapter;
import com.facebook.drawee.view.SimpleDraweeView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/11/17.
 */

public class TagDetailsArticlesRecycleViewAdapter extends BaseRecycleViewAdapter<ArticlesBean> {

    public TagDetailsArticlesRecycleViewAdapter(Context context) {
        super(context);
    }
    private int maxCount;

    public int getMaxCount() {
        return maxCount;
    }

    public void setMaxCount(int maxCount) {
        this.maxCount = maxCount;
    }

    @Override
    public int getItemCount() {
        if(maxCount == 0){
            return super.getItemCount();
        }
        if(this.maxCount < super.getItemCount()){
            return this.maxCount;
        }
        return super.getItemCount();
    }
    @Override
    protected int getHeaderItemCount() {
        return 0;
    }

    @Override
    protected int getFooterItemCount() {
        return 0;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflaterView(R.layout.list_item_tag_details_article, parent);
        return new ItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ArticlesBean articlesBean = getItem(position);
        ItemViewHolder viewHolder = (ItemViewHolder) holder;
        viewHolder.imageViewArticleTopImage.setImageURI(articlesBean.getFeaturedImageUrl());
        viewHolder.textViewArticleMainTitle.setText(articlesBean.getTitle());
        viewHolder.textViewArticleNumLiked.setText(articlesBean.getLikeCount()+"");
        viewHolder.textViewNumReviews.setText(articlesBean.getHitCount()+"");
        if(position == 0){
            viewHolder.bottomBar.setVisibility(View.GONE);
        }
    }
    class ItemViewHolder extends BaseRecycleViewAdapter.BaseViewHolder {
        @BindView(R.id.bottom_bar)
        View bottomBar;
        @BindView(R.id.imageView_article_top_image)
        SimpleDraweeView imageViewArticleTopImage;
        @BindView(R.id.textView_article_main_title)
        TextView textViewArticleMainTitle;
        @BindView(R.id.textView_article_num_liked)
        TextView textViewArticleNumLiked;
        @BindView(R.id.textView_num_reviews)
        TextView textViewNumReviews;

        ItemViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
